#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# author    : Xiangwei Wang
# email     : wangxw-cn@qq.com
# datetime  : 2021/4/29 20:46

"""
"""

import json
import copy

user_feature_file = "../../Data/user_feature.json"
time_feature_file = "../../Data/time_feature_1.json"
content_feature_file = "../../Data/content_feature_4.json"

users = {}
print("开始读取时间特征")
with open(time_feature_file, "r", encoding='utf-8') as f2:
    users = json.load(f2)
    print(f"时间特征读取完成，用户数量：{len(users.keys())}")

cnt = 0
print("开始读取用户特征")
with open(user_feature_file, "r", encoding='utf-8') as f1:
    all_users = json.load(f1)
    for u in all_users:
        cnt += 1
        for k in all_users[u]:
            users[u][k] = copy.deepcopy(all_users[u][k])
    print(f"用户特征读取完成，用户数量：{cnt}")

print("开始读取博文特征")
cnt = 0
blog_cnt = 0
with open(content_feature_file, "r", encoding='utf-8') as f3:
    all_users = json.load(f3)
    for u in all_users:
        cnt += 1
        for blog in all_users[u]["blogs"]:
            blog_cnt += 1
            for k in all_users[u]["blogs"][blog]:
                users[u]["blogs"][blog][k] = copy.deepcopy(all_users[u]["blogs"][blog][k])
    print(f"博文特征读取完成，用户数量：{cnt}，博文数量：{blog_cnt}")
print("开始写入json")

# ======= 写入json ===========：
jsonStr = json.dumps(users, ensure_ascii=False)
with open("../../Data/feature_sum.json", "w", encoding='utf-8') as f:
    f.write(jsonStr)
print("完成")